<%-- 
    Document   : group
    Created on : 19-feb-2011, 21:17:57
    Author     : Alexandre
--%>

<%@page import="model.Payment"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.Collection"%>
<%@page import="model.Recepit"%>
<%@page import="model.GroupDefinition"%>
<%@page import="model.User"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!doctype html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>

        <%
        User myself = null;        
             if (session != null) {
                 myself = (User) session.getAttribute("user");
                 if (myself == null) {
                     response.sendRedirect("index.jsp");
                 }
             } else {
                 response.sendRedirect("index.jsp");
             }
        GroupDefinition group = (GroupDefinition)request.getAttribute("group");
        if(group == null){
            response.sendRedirect("homePage.jsp");
        }                         
        %>
        <h1>Wellcome to group </h1>
        <div id="dashboard">
            <div id ="firstRow">
                <div id="receiptList">
                    <ul>
                        <% Collection<Recepit> list = group.getRecepitCollection();
                        if(list != null){
                            int size = list.size();
                            Iterator<Recepit> it = list.iterator();
                            for(int i=0;i<5 && it.hasNext() ;i++){
                        %>
                        <li>
                            <div class="receipt">
                                <%  Recepit rec =  it.next();%>
                                <%=rec.getTimestamp().toString()%>
                                <%=rec.getConcept()%>
                                <%=rec.getPayer().getUsername()%>
                            </div>
                        </li>
                        <%
                          }
                      }%>
                    </ul>  
                    <div id="newreceipt">
                        <form action="Controller">
                            <input type="hidden" name="action" value="newreceipt" />
                            Concepto <input type="text" name="concept" value="New concept" />
                            Cantidad <input type="text" name="quantity" value ="000" />
                            <input type="submit" value="Add" />
                        </form>
                    </div>
                </div>
                <div id="paymentList">
                    <ul>
                        <% Collection<Payment> payList = group.getPaymentCollection();
                         if(payList != null){
                             int size = payList.size();
                             Iterator<Payment> it = payList.iterator();
                             for(int i=0;i<5 && it.hasNext() ;i++){
                        %>
                        <li>
                            <div class="receipt">
                                <%  Payment pay =  it.next();%>
                                <%=pay.getTimestamp().toString()%>
                                <%=pay.getFromUser().getUsername()%>
                                <%=pay.getToUser().getUsername()%>
                            </div>
                        </li>
                        <%
                                }
                            }%>
                    </ul>
                    <div id="newpayment">
                        <form action="Controller">
                            <input type="hidden" name="action" value="newpayment" />
                            Persona <input type="text" name="target" value="Target" />
                            Cantidad <input type="text" name="quantity" value ="000" />
                            <input type="submit" value="Add" />
                        </form>
                    </div>
                </div>

            </div>
            <div id ="lastRow">
                <div id="messageList">

                </div>
                <div id="statistics">

                </div>

            </div>
        </div>
    </body>
</html>
